import MINEGOlogic as mglogic
import sys
def print_menu() -> int:
    # 打印游戏菜单
    menu_items = [
        "M. 开始新游戏",
        "I. 加载存档",
        "N. 查看规则",
        "E. 退出"
    ]
    
    border = "-----------------------------------------------------------"
    title = "MINEGO!"
    
    print(border)
    print(f"------------------------{title}----------------------------")
    print(border)
    for item in menu_items:
        print(f"------{item}-------------------")
    print(border)
    print(border)
    return 0

def handle_user_input(choice : str) -> int:
    # 根据用户输入执行相应的操作
    if choice == 'M':
        print("开始新游戏...")
        mglogic.newGame()
    elif choice == 'I':
        print("加载存档...")
        mglogic.loadGame()
    elif choice == 'N':
        print("查看规则...")
        mglogic.seeRules()
    elif choice == 'E':
        print("退出游戏...")
        sys.exit(0)
    else:
        print("无效的选择，请重新输入。")
    return 0

def main():
    # 主函数，显示菜单并处理用户输入
    while True:
        print_menu()
        choice = input("请输入您的选择: ").strip().upper()
        handle_user_input(choice)

if __name__ == "__main__":
    main()